const sequelizeError = async (ctx: any, next: any) => {
  ctx.seqErr = (error: any) => {
    console.log(error)
    let err = error
    if (error) {
      switch (error.name) {
        // 唯一约束错误
        case 'SequelizeUniqueConstraintError':
          err = {
            name: 'SequelizeUniqueConstraintError',
            msg: error.errors[0].path + ' 已存在',
          }
          break
      }
    }
    return err
  }
  await next()
}

export default sequelizeError
